package com.example.zhihuhelpapp.utils;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.example.zhihuhelpapp.R;

import java.util.Random;
import java.util.UUID;

import static android.content.Context.NOTIFICATION_SERVICE;

public class NotificationUtils {
    public static final String CHANNEL_ID = "com.example.zhihuhelpapp.channel";

    @SuppressLint("NewApi")
    public static boolean isNotificationEnabled(Context context) {
        NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context);
        return managerCompat.areNotificationsEnabled();
    }

    /**
     * 优选版本通知发送
     */
    public static void send(Context context, Intent intent, String title, String text) {
        PendingIntent pendingIntent16 = PendingIntent.getActivity(context, UUID.randomUUID().hashCode(),
                intent, 0);
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                .setContentTitle(title)
                .setContentText(text)
                .setDefaults(Notification.DEFAULT_ALL)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setPriority(NotificationManager.IMPORTANCE_HIGH)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.icon_jd_logo)
                .setVibrate(new long[] {0,300,500,700})
                .setContentIntent(pendingIntent16)
                .setAutoCancel(true)
                .build();
        if (manager != null) {
            manager.notify(new Random().nextInt(), notification);
        }

    }

}
